﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ITAP.ShprossesBuilder.Modelling.Components;
using ITAP.Core.Modelling.Primitives;
using ITAP.ShprossesBuilder.Modelling;
using ITAP.ShprossesBuilder.Calculations;
using ITAP.ShprossesBuilder.Properties;

namespace ITAP.ShprossesBuilder.Operations
{
    public class OperationCreateCrossConnectorsOnShprosses : IOperation
    {
        #region IOperation Members

        public string Name
        {
            get { return "Создать соединение по пересечению профилей"; }
        }

        public OperationGroup OperationGroup
        {
            get { return OperationGroup.ShprossOperation; }
        }

        public System.Drawing.Image Thumbnail
        {
            get { return Resources.ShprossCreateCrossConnector.ToBitmap(); }
        }

        public void Execute(ModelControl modelControl)
        {
            Shpross shpross1 = null;
            Shpross shpross2 = null;


            int counter = 0;
            foreach (IComponent selectedComponent in modelControl.ModelContainer.SelectedComponentsStack)
            {
                if (selectedComponent is Shpross)
                {
                    if (counter == 0)
                        shpross1 = selectedComponent as Shpross;
                    else if (counter == 1)
                        shpross2 = selectedComponent as Shpross;
                    else
                        break;
                    counter++;
                }
            }


            if (shpross1 == null || shpross2 == null)
                return;

            ComponentFactory.CreateCrossConnectorsByShprosses(shpross1, shpross2, null);
   
            modelControl.UpdateModel();
        }

        public bool CanUndo
        {
            get { return true; }
        }

        #endregion
    }
}
